home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Classes / XText / XTAction.h < prev    next >
Encoding:
Text File  |  1992-04-14  |  3.3 KB  |  129 lines

  1. /*    This file is part of the XText package (version 0.8)
  2.     Mike Dixon, April 1992
  3.     
  4.     Copyright (c) 1992 Xerox Corporation.  All rights reserved.
  5.  
  6.     Use and copying of this software and preparation of derivative works based
  7.     upon this software are permitted.  This software is made available AS IS,
  8.     and Xerox Corporation makes no warranty about the software or its
  9.     performance.
  10. */
  11.  
  12. #import <objc/Object.h>
  13. #import <dpsclient/event.h>
  14.  
  15. /*    An XTAction specifies the action to be taken in response to a key event.
  16.     When a key event occurs, the applyTo:event: method is invoked; this is
  17.     the key method that must be implemented by the subclasses of XTAction.
  18.  
  19.     Actions normally return self from the applyTo:event: method, but by
  20.     returning nil they can cause the event to be handled normally by XText0's
  21.     superclass (i.e. Text).
  22.  
  23.     The class method undefinedAction returns a default action that invokes
  24.     the text object's unboundKey method.
  25. */
  26.  
  27. @interface XTAction:Object
  28. {
  29. }
  30. + undefinedAction;
  31. - applyTo:xtext event:(NXEvent *)event;
  32. @end
  33.  
  34. #define MAPPED_KEYS      81                //    table size for a dispatch action
  35. #define KEY_CODES  (MAPPED_KEYS * 16)    //    4 modifiers = 16 combinations/key
  36.  
  37. /* keyCodes are 16 * event->data.key.keyCode,
  38.         + 1 if control,
  39.         + 2 if shift,
  40.         + 4 if alt,
  41.         + 8 if command
  42. */
  43.  
  44. typedef int keyCode;
  45. typedef XTAction *actionTbl[KEY_CODES];
  46.  
  47. /*    XTMsg0Action, XTMsg1Action, and XTMsg2Action are subclasses of XTAction
  48.     that send a specified message to the text object with 0, 1, or 2 args.
  49. */
  50.  
  51. @interface XTMsg0Action:XTAction
  52. {
  53.     SEL    action_sel;
  54. }
  55. - initSel:(SEL)sel;
  56. @end
  57.  
  58. @interface XTMsg1Action:XTAction
  59. {
  60.     SEL    action_sel;
  61.     int action_arg;
  62. }
  63. - initSel:(SEL)sel arg:(int)arg;
  64. @end
  65.  
  66. @interface XTMsg2Action:XTAction
  67. {
  68.     SEL    action_sel;
  69.     int action_arg1;
  70.     int action_arg2;
  71. }
  72. - initSel:(SEL)sel arg:(int)arg1 arg:(int)arg2;
  73. @end
  74.  
  75. /*    XTDispatchAction is a subclass of XTAction that maintains a dispatch
  76.     table of other actions and selects one based on the key pressed.  The
  77.     methods are
  78.         initBase:estream:    the first argument is a string naming a 'base'
  79.                             set of initial bindings; the only values currently
  80.                             supported are "emacs" and "none"
  81.         bindKey:toAction:estream:
  82.                             bind a key to a specified action; an action of nil
  83.                             will cause the key to be handled normally by the
  84.                             Text class
  85.         addBindings:estream:
  86.                             parse and install the bindings specified by a
  87.                             string
  88.  
  89.     The estream argument is used to report any errors; if it is nil, the
  90.     default error stream (which simply pops up an alert panel) is used.
  91. */
  92.  
  93. @interface XTDispatchAction:XTAction
  94. {
  95.     actionTbl actions;
  96. }
  97. - initBase:(const char *)base estream:errs;
  98. - bindKey:(keyCode)key toAction:action estream:errs;
  99. @end
  100.  
  101. @interface XTDispatchAction(parsing)
  102. - addBindings:(const char *)bindings estream:errs;
  103. @end
  104.  
  105. /*    XTEventMsgAction is a subclass of XTAction that sends a specified
  106.     message to the text object, passing the event as an argument.
  107.     This is useful for implementing some special-purpose prefix commands
  108.     like 'quote next character'
  109. */
  110.  
  111. @interface XTEventMsgAction:XTAction
  112. {
  113.     SEL action_sel;
  114. }
  115. - initSel:(SEL)sel;
  116. @end
  117.  
  118. /*    XTSeqAction is a subclass of XTAction that invokes a sequence of
  119.     subactions.
  120. */
  121.  
  122. @interface XTSeqAction:XTAction
  123. {
  124.     int length;
  125.     XTAction **actions;
  126. }
  127. - initLength:(int)len actions:(XTAction **)acts;
  128. @end
  129.